package org.openfans.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openfans.domain.Facade;
import org.openfans.domain.Article;
import org.openfans.util.ThreadFans;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class JudgeArticleController extends AbstractController {
	private Facade facade = null;

	public void setFacade(Facade facade) {
		this.facade = facade;
	}

	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ThreadFans.authorize();
		String articleId = request.getParameter("id");
		String use = request.getParameter("use");
//		Fans fans = ThreadFans.get();
		Article article = facade.getArticle(Integer.parseInt(articleId));
		if ("used".equals(use)) {
			article.addUsedNum(1);
		} else if ("useless".equals(use)) {
			article.addUselessNum(1);
		}
		facade.save(article);

		return new ModelAndView("redirect:viewArticle.html?id=" + articleId);
	}
}
